<?
/**
 * VoiceOne Settings/Rules/outgoing/edit
 *
 * Frontend to provide access to the rules system in voiceone.
 * @package voiceone
 * @subpackage  settings_rules
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  
  //================ PAGE LOGIC ================
  if (count($_POST)>0) {

    $entry=Array(
      "id" => $_POST["id"],
      "name" => $_POST["name"],
      "description" => $_POST["description"],
      "type" => RULE_OUTGOING 
    );

    //save the group informations
    $ret=$asterisk->putRule($entry);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".$cwlang["ruleout"]["createRulesetYes"]."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".$cwlang["ruleout"]["createRulesetNo"]."</div>";
    
    goToMainPage($alert);
  }
  //--------------------------------------------------------------------------
  
  //if modify, read the group informations
  if (isset($_GET["id"])) {
    $ret=$asterisk->getRule($_REQUEST["id"],RULE_OUTGOING);
    if ($err=$asterisk->getError()) die("Error: $err");
    $id=$ret[0]["id"];
    $name=$ret[0]["name"];
    $description=$ret[0]["description"];
    
    // the name can't be changed, because of it is written all over the asterisk
    $disableName=" disabled=\"disabled\" ";
  }  
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="outgoing";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$cwlang["ruleout"]["editTitle"]?></h1>
    <h3><a href="../" class="admin" ><?=$cwlang["ruleout"]["return"]?></a></h3>
  </div>
  
  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post" >
      
      <p class="blockintro"></p>
      <div class="block">
        <table>
          <tr>
            <td class="required"><label for="name"><?=$cwlang["ruleout"]["Name"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="name" name="name" value="<?=$name?>" <?=$disableName?>/></td>
          </tr>
          <tr>
            <td class="required"><label for="description"><?=$cwlang["ruleout"]["Description"]?>:</label></td>
            <td><textarea rows="10" cols="40" id="description" name="description"><?=$description?></textarea></td>
          </tr>
        </table>
      </div>

    <div class="action">
      <?if (isset($_GET["id"])) {?><input type="hidden" name="id" value="<?=$id?>" /><input type="hidden" name="name" value="<?=$name?>" /><?}?>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Cancel" onclick="location.href='../'; return false;"/>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" />
    </div>
  </form>
 </div>  
  
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=$cwlang["ruleout"]["editSB"]?></h1>
          <p><?=$cwlang["ruleout"]["editSBdesc"]?></p>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "rules");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

